<?php
$version = Zend_Registry::get('version');
$this->templatesForm->setEditor($this->serverUrl().$this->baseUrl());
$this->templatesForm->getEditor();
?>

<script type="text/javascript">
$(document).ready(function() {
	floatingbar('#floatingbar',"#button_top_bar",null);
	$('a.reset_btn').click(function() {			
		 resetFields();	
		 removeError();	
	});
	function resetFields()
	{
		$( "form" )[ 0 ].reset();		
	}
	
	function removeError()
	{
		$('#actionMessage').attr('class','none');
		$('#actionMessage').html('&nbsp;');
					
		$.each($('form').serializeArray(), function(i, field) {				
				$('#'+field.name).removeClass('ui-state-error');
				$('#'+field.name+'_err').html('');									
		});				
	}
	
	function getFormData()
	{
		var fieldObj = {};
		$.each($('form').serializeArray(), function(i, field) {			
			if(tinyMCE.get(field.name))
			{
				fieldObj[field.name] = tinyMCE.get(field.name).getContent();
			}
			else
			{
				fieldObj[field.name] = field.value;
			}						
		});
		fieldObj['id'] = <?php echo $this->id; ?>;
		return fieldObj;
	}
	
	function addError(key,errMsg)
	{
		var err_id = key+'_err';
		var field_name = key;
		$('#'+field_name).addClass('ui-state-error');
		$('#'+err_id).append(errMsg);
	}
	
	function openLoaderDialog()
	{
		$('#dialog_container').dialog({
					autoOpen: true,
					modal: true,
					show: 'fade',
					resizable: 'false',				
					open: function(event, ui)
						 {
						 	$("#progressbar").progressbar({
								value:100
				
							});							
						  }
				});
	}
	
	function closeLoaderDialog()
	{
		$('#dialog_container').dialog('option','hide','explode').dialog('close');
	}
	
	$('a.edit_template_btn').click(function() {			
			
			removeError();
			openLoaderDialog();	
			var formData = getFormData();			
			
		$.ajax({
			url: "<?php echo $this->url( array('module' => 'Newsletter','controller' => 'Templates', 'action'     => 'edit' ), 'adminrout',    true) ?>",
			  	type: 'POST',
			  	data: formData,
				success: function(response){
					//alert(response);					
					var json_arr = eval("("+response+")");					
					closeLoaderDialog();					
					if(json_arr.status == 'ok')
					{
						$('#actionMessage').html(succMsgDesign(json_arr.msg));														
					}
					else if(json_arr.status == 'errV')
					{
						$('#actionMessage').html(errMsgDesign("<?php echo $this->translator->translator('common_err'); ?>"));
												
						for(var i= 0; i < json_arr.msg.length; i++)
						{
							addError(json_arr.msg[i].key,json_arr.msg[i].value);							
						}
					}
					else
					{
						$('#actionMessage').html(errMsgDesign(json_arr.msg));
					}
				},
				error: function(xhr, status, error){
					closeLoaderDialog();
					var msg = "Error! " + xhr.status + " " + error;
					$('#actionMessage').html(errMsgDesign(msg));
				}
		});
	});		
	
});


</script>
<div id="container">
<?php if (!$this->allow()) : ?>
	<div class="grid_12 t_a_bottom">
		<?php echo $this->translator->translator('Member_Access_deny_desc'); ?>
	</div>
<?php else : ?>

<div class="title-container">
	<div class="newsletter-edit"><h1><?php echo $this->translator->translator('newsletter_temp_edit_page_name'); ?></h1></div>
    
    <div class="button-container">
        <span class="button ui-widget-content-1"><a href="<?php echo $this->url( array('module' => 'Newsletter','controller' => 'Templates', 'action'     => 'list' ), 'adminrout',    true) ?>"><span class="icon back"><?php echo $this->translator->translator('common_back'); ?></span></a></span>
        <span class="button ui-widget-content-1"><a href="javascript:  void(0);" class="reset_btn"><span class="icon reset"><?php echo $this->translator->translator('common_reset'); ?></span></a></span>
        <span class="button ui-widget-content-1"><a href="javascript: void(0);" class="edit_template_btn"><span class="icon save"><?php echo $this->translator->translator('common_save'); ?></span></a></span>
    </div>
</div>
<div id="button_top_bar"></div>
<div class="content-container">
	<div id="actionMessage"></div>
   	
    <form name="formNews" id="formNews" method="post">
    	<div id="generalInfo">
        	<fieldset class="fieldset last">
            	<legend class="legend"><?php echo $this->translator->translator('newsletter_temp_add_page_general_info'); ?></legend>
                <div class="form">
                    <div class="form-row">
                        <div class="label article-label">
                            <?php echo $this->templatesForm->templates_name->getLabel(); if($this->templatesForm->templates_name->isRequired()){?><span class="required">*</span><?php } ?>
                        </div>
                        
                        <div class="field article-field">
                            <?php  echo $this->templatesForm->templates_name; ?>
                            <div class="ui-widget ui-helper-clearfix info"><div class="ui-widget-header ui-corner-all" title="<?php echo $this->escape($this->templatesForm->templates_name->getAttrib('title')); ?>"><p><span class="ui-icon ui-icon-info"></span></p></div></div>
                            <div class="input-errors" id="templates_name_err"></div>
                        </div>
                    </div>
                    
                    <div class="form-row">
                        <div class="label article-label">
                            <?php echo $this->templatesForm->templates_title->getLabel(); if($this->templatesForm->templates_title->isRequired()){?><span class="required">*</span><?php } ?>
                        </div>
                        
                        <div class="field article-field">
                            <?php echo $this->templatesForm->templates_title; ?>
                            <div class="ui-widget ui-helper-clearfix info"><div class="ui-widget-header ui-corner-all" title="<?php echo $this->escape($this->templatesForm->templates_title->getAttrib('title')); ?>"><p><span class="ui-icon ui-icon-info"></span></p></div></div>
                            <div class="input-errors" id="templates_title_err"></div>
                        </div>
                    </div>
                    
                    <div class="form-row">
                        <div class="label article-label">
                            <?php echo $this->templatesForm->templates_page->getLabel(); if($this->templatesForm->templates_page->isRequired()){?><span class="required">*</span><?php } ?>
                        </div>
                        
                        <div class="field article-field">
                            <?php echo $this->templatesForm->templates_page; ?>
                            <div class="ui-widget ui-helper-clearfix info"><div class="ui-widget-header ui-corner-all" title="<?php echo $this->escape($this->templatesForm->templates_page->getAttrib('title')); ?>"><p><span class="ui-icon ui-icon-info"></span></p></div></div>
                            <div class="input-errors" id="templates_page_err"></div>
                        </div>
                    </div>
                    
                    <div class="form-row">
                        <div class="label article-label">
                            <?php echo $this->templatesForm->templates_desc->getLabel(); if($this->templatesForm->templates_desc->isRequired()){?><span class="required">*</span><?php } ?>
                        </div>
                        
                        <div class="field article-field">
                            <div class="editor"><?php echo $this->templatesForm->templates_desc; ?></div>
                           	<div class="ui-widget ui-helper-clearfix info"><div class="ui-widget-header ui-corner-all" title="<?php echo $this->escape($this->templatesForm->templates_desc->getAttrib('title')); ?>"><p><span class="ui-icon ui-icon-info"></span></p></div></div>
                            <span id="loaderLink"><a href="javascript:void(0);" onClick="loadTinyMCE('templates_desc');"><img src="application/modules/Administrator/layouts/scripts/images/common/editors.gif" border="0" title="<?php echo $this->translator->translator('common_editor_open'); ?>" alt="<?php echo $this->translator->translator('common_editor_open'); ?>" ></a></span>
                            <div class="input-errors" id="templates_desc_err"></div>
                        </div>
                    </div>
                </div>
			</fieldset>
        </div>
	</form>
	
    <div class="button-container">
        <span class="button ui-widget-content-1"><a href="<?php echo $this->url( array('module' => 'Newsletter','controller' => 'Templates', 'action'     => 'list' ), 'adminrout',    true) ?>"><span class="icon back"><?php echo $this->translator->translator('common_back'); ?></span></a></span>
        <span class="button ui-widget-content-1"><a href="javascript:  void(0);" class="reset_btn"><span class="icon reset"><?php echo $this->translator->translator('common_reset'); ?></span></a></span>
        <span class="button ui-widget-content-1"><a href="javascript: void(0);" class="edit_template_btn"><span class="icon save"><?php echo $this->translator->translator('common_save'); ?></span></a></span>
    </div>
</div>

<div id="floatingbar">
	<h1><?php echo $this->translator->translator('newsletter_temp_edit_page_name'); ?></h1>
    
    <div class="button-container">
        <span class="button ui-widget-content-1"><a href="<?php echo $this->url( array('module' => 'Newsletter','controller' => 'Templates', 'action'     => 'list' ), 'adminrout',    true) ?>"><span class="icon back"><?php echo $this->translator->translator('common_back'); ?></span></a></span>
        <span class="button ui-widget-content-1"><a href="javascript:  void(0);" class="reset_btn"><span class="icon reset"><?php echo $this->translator->translator('common_reset'); ?></span></a></span>
        <span class="button ui-widget-content-1"><a href="javascript: void(0);" class="edit_template_btn"><span class="icon save"><?php echo $this->translator->translator('common_save'); ?></span></a></span>
    </div>
</div>
<?php endif; ?>	
<div id="dialog_container" style="display:none" title="<?php echo $this->translator->translator('common_processing_language'); ?>">
	<div id="progressbar" ></div>	
</div>
</div>
